<?php
/**************************************************
 *  MeatBallBot Web-Interface v0.4a               *
 *                                                *
 *  Licenced under the GPLv3                      *
 *                                                *
 *  Originally coded by HttpError (Jordan Songer) *
 **************************************************/ 
include("../inc/include.php");
//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])) 
{ 
  $user = $_COOKIE['ID_my_site']; 
  $pass = $_COOKIE['Key_my_site']; 
  $check = mysql_query("SELECT * FROM users WHERE user = '$user'")or die("Ohnoes. Report ERROR:100/300/".mysql_errno()." to an admin."); 
  while($info = mysql_fetch_array( $check )) 
  { 

    //if the cookie has the wrong password, they are taken to the login page 
    if ($pass != $info['password']) 
    { 
      header("Location: ../index.php"); 
    } 
    else 
    {
      $errors=0;
      $error="The following errors occured while processing your form input.<ul>";
      $network = mysql_escape_string($_POST['network']);
      $channel = mysql_escape_string($_POST['channel']);
      $calc = mysql_escape_string($_POST['calc']);
      $chanman = mysql_escape_string($_POST['chanman']);
      $factoid = mysql_escape_string($_POST['factoid']);
      $game = mysql_escape_string($_POST['game']);
      $search = mysql_escape_string($_POST['search']);
      $delay = mysql_escape_string($_POST['delay']);
      $callsign = mysql_escape_string($_POST['callsign']);
      if ($network=="" || $channel=="" || $callsign=="" )
      {
        $errors=1;
        $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
      }
      if($errors==1)
      {
        die($error);
      } else {
        $checkin = mysql_query('SELECT * FROM `channels` WHERE channame='.$channel.' AND netid='.$network.'') or die("Ohnoes. Report ERROR:100/301/".mysql_errno()." to an admin.");
        if (mysql_num_rows($checkin) > 0)
        {
          die("I am already in that Channel ^.^");
        } else {
          if ($info['chanid'] == $null || $info['chanid'] == "")
          {
            mysql_query('INSERT INTO `channels` (`channame`, `netid`, `ownerid`, `callsign`, `delay`) VALUES ('.$channel.', '.$network.', '.$info["id"].', '.$callsign.', '.$delay.')') or die("Ohnoes. Report ERROR:100/302/".mysql_errno()." to an admin.");
            $m_lastid = mysql_insert_id();
            mysql_query('INSERT INTO `users` (`chanid`) VALUES ('.$m_lastid.') WHERE id='.$info["id"].'') or die("Ohnoes. Report ERROR:100/303/".mysql_errno()." to an admin.");
          } else {
            mysql_query('INSERT INTO `channels` (`channame`, `netid`, `ownerid`, `callsign`, `delay`) VALUES ('.$channel.', '.$network.', '.$info["id"].', '.$callsign.', '.$delay.')') or die("Ohnoes. Report ERROR:100/304/".mysql_errno()." to an admin.");
          }
        }
      }
?>

<h2>Thank you!</h2>

<table width=50%>
<tr><td>network: </td><td> <?php echo $network; ?> </td></tr>
<tr><td>channel: </td><td> <?php echo $channel; ?> </td></tr>
<tr><td>calc: </td><td> <?php echo $calc; ?> </td></tr>
<tr><td>chanman: </td><td> <?php echo $chanman; ?> </td></tr>
<tr><td>factoid: </td><td> <?php echo $factoid; ?> </td></tr>
<tr><td>game: </td><td> <?php echo $game; ?> </td></tr>
<tr><td>search: </td><td> <?php echo $search; ?> </td></tr>
<tr><td>delay: </td><td> <?php echo $delay; ?> </td></tr>
<tr><td>callsign: </td><td> <?php echo $callsign; ?> </td></tr>
</table>

<?php 
    }
  }
} else { header("Location: ../index.php"); }

?>
